import structs/HashMap
import [BuiltIn,Value]

Scope : class {
    parent : Scope {
        get
        set(pScope) { // When setting a parent scope
            for(key in pScope values getKeys()) { //Make sure the heritage comes to you :)
                this[key] = pScope values[key] // (copy all the values from the parent scope)
            }
        }
    }
    
    values := HashMap<String,Value> new()

    init : func {
        BuiltIn fill(this)
    }
    
    add : func(name : String, value : Value) {
        values[name] = value
    }
    
    remove : func(name : String) {
        values remove(name)
    }
    
    contains? : func(name : String) -> Bool {
        values contains?(name)
    }
}

operator [] (scope : Scope, name : String) -> Value {
    scope values get(name) as Value
}

operator []= (scope : Scope, name : String, value : Value) {
    scope add(name,value)
}